package com.chinanet.netelementmodel;

import com.chinanet.entry.netelement.Attr;
import com.chinanet.entry.netelement.AttrType;
import com.chinanet.entry.netelement.WorkInterFace;
import com.chinanet.utils.pon.HW_Socket_AttrsIn;
import com.chinanet.utils.pon.OperationType;
import com.chinanet.utils.pon.ZX_SocketClient;

import java.util.HashMap;
import java.util.Map;
/**
 * @description Created by jwing on 2018/1/15.
 * 中兴PON网管-激活、复位ONU
 */
public class ZX_RESET_ONU_Imp implements WorkInterFace {
    @Override
    public String getName() {
        return "中兴PON网管-激活、复位ONU";
    }

    @Override
    public String getDesciption() {
        return "";
    }

    @Override
    public int getVersion() {
        return 0;
    }

    @Override
    public Attr[] getInAttrs() {
        Attr[] in = new Attr[2];
        in[0] = new Attr("DID", "OLT的ID", AttrType.TYPE_String, true);
        in[1] = new Attr("OID", "ONU端口ID，通过“机架-框-槽号-端口”的方式定位，没有的补为“NA”。", AttrType.TYPE_String, true);
        return in;
    }

    @Override
    public Attr[] getOutAttrs() {
        Attr[] out = new Attr[2];
        out[0] = new Attr("flag", "操作是否成功，1：成功，0：失败", AttrType.TYPE_Int, true);
        out[1] = new Attr("log", "日志文件", AttrType.TYPE_String, true);
        return out;
    }

    @Override
    public Map<String, Object> init(Map<String, Object> data) {
        Map<String, Object> outmap = new HashMap<>();
        String ip ="134.103.235.44";
        int port = 9820;
        ZX_SocketClient hclient = new ZX_SocketClient(ip, port);
        HW_Socket_AttrsIn attrsin = new HW_Socket_AttrsIn();
        attrsin.setONUID((String)data.get("DID"));
        attrsin.setONUPORT((String)data.get("OID"));
        Map<String, Object> inmap = hclient.init(attrsin,
                OperationType.TYPE_RESET_ONU);

        boolean flag = (Boolean) inmap.get("flag");
        if(flag) {
            outmap.put("flag", 1);
        } else {
            outmap.put("flag", 0);
        }
        outmap.put("log", inmap.get("log"));

        return outmap;
    }
}
